home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / TIMER.H < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-18  |  1.9 KB  |  57 lines

  1. #ifndef    TIMER_STOP
  2.  
  3. #include "global.h"
  4.  
  5. /* Software timers
  6.  * There is one of these structures for each simulated timer.
  7.  * Whenever the timer is running, it is on a doubly-linked list
  8.  * pointed to by "Timers". The list is sorted in ascending order of
  9.  * expiration, with the next timer to expire at the head. Each timer's
  10.  * count field contains only the additional INCREMENT over all preceeding
  11.  * timers; this allows the hardware timer interrupt to decrement only the
  12.  * first timer on the chain until it hits zero.
  13.  *
  14.  * Stopping a timer or letting it expire causes it to be removed
  15.  * from the list. Starting a timer puts it on the list at the right
  16.  * place. These operations have to be careful about adjusting the count
  17.  * field of the next entry in the list.
  18.  */
  19. struct timer {
  20.     struct timer *next;    /* Doubly-linked-list pointers */
  21.     struct timer *prev;
  22.     int32 start;        /* Period of counter (load value) */
  23.     int32 count;        /* Ticks to go until expiration */
  24.     void (*func)();        /* Function to call at expiration */
  25.     void *arg;        /* Arg to pass function */
  26.     char state;        /* Timer state */
  27. #define    TIMER_STOP    0
  28. #define    TIMER_RUN    1
  29. #define    TIMER_EXPIRE    2
  30. };
  31. #define    NULLTIMER    (struct timer *)0
  32. #define    MAX_TIME    (int32)4294967295    /* Max long integer */
  33. #define    MSPTICK        55        /* Milliseconds per tick */
  34. /* Useful user macros that hide the timer structure internals */
  35. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  36. #define    dur_timer(t)    ((t)->start)
  37. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  38.  
  39. extern int32 Clock;    /* Count of ticks since start up */
  40.  
  41. #if    defined(__STDC__) || defined(__TURBOC__)
  42. void alarm(int32 ticks);
  43. void start_timer(struct timer *t);
  44. void stop_timer(struct timer *t);
  45. int32 read_timer(struct timer *t);
  46. void pause(int32 ticks);
  47. #else
  48. void alarm();
  49. void start_timer(),stop_timer();
  50. int32 read_timer();
  51. void pause();
  52. #endif
  53.  
  54. #endif    /* TIMER_STOP */
  55.  
  56.  
  57.